﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Xml.Serialization;

namespace Programonica.Igramonica.Core
{
    public class Settings
    {
        #region Graphics Settings

        public bool IsFullScreen;

        public int Width;

        public int Height;

        public int RefreshRate;

        public bool SynchronizeWithVerticalRetrace;

        #endregion

        #region Load/Save code

        /// <summary>
        /// Saves the current settings
        /// </summary>
        /// <param name="filename">The filename to save to</param>
        public void Save(string filename)
        {
            using (Stream stream = File.Create(filename))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                serializer.Serialize(stream, this);
            }
        }

        /// <summary>
        /// Loads settings from a file
        /// </summary>
        /// <param name="filename">The filename to load</param>
        public static Settings Load(string filename)
        {
            using (Stream stream = File.OpenRead(filename))
            {
                XmlSerializer serializer = new XmlSerializer(typeof(Settings));
                return (Settings)serializer.Deserialize(stream);
            }
        }
        #endregion
    }
}
